1
|
|
|
// We declare and use this function to make clear to the minifier that the eval will not effect the later parts of the script despite being called there. |
2
|
|
|
var exec = function(s) { |
3
|
|
|
eval(s); |
|
|
|
|
4
|
|
|
}; |
5
|
|
|
(function() { |
6
|
|
|
"use strict"; |
7
|
|
|
var updateRefreshTimeout, refreshSpeed, ajaxRunning = true, refreshReady = true, disableStartAJAX=true, xmlHttpRefresh, sn, stopAJAX; |
8
|
|
|
|
9
|
|
|
// startAJAX |
10
|
|
|
window.onfocus = function() { |
11
|
|
|
// Start the Ajax updates if startRefresh has been called |
12
|
|
|
if(!disableStartAJAX) { |
13
|
|
|
ajaxRunning = true; |
14
|
|
|
clearTimeout(updateRefreshTimeout); |
15
|
|
|
updateRefreshRequest(); |
16
|
|
|
} |
17
|
|
|
}; |
18
|
|
|
|
19
|
|
|
// pauseAJAX |
20
|
|
|
window.onblur = function() { |
21
|
|
|
// Pause the Ajax updates |
22
|
|
|
ajaxRunning = false; |
23
|
|
|
}; |
24
|
|
|
|
25
|
|
|
window.onunload = stopAJAX = function() { |
26
|
|
|
// Stop the Ajax updates |
27
|
|
|
clearTimeout(updateRefreshTimeout); |
28
|
|
|
disableStartAJAX=true; |
29
|
|
|
ajaxRunning = false; |
30
|
|
|
if (xmlHttpRefresh !== undefined) { |
31
|
|
|
xmlHttpRefresh.abort(); |
32
|
|
|
} |
33
|
|
|
}; |
34
|
|
|
|
35
|
|
|
function getURLParameter(paramName, href) { |
36
|
|
|
if ( href.indexOf("?") > -1 ) { |
37
|
|
|
var paramList = href.substr(href.indexOf("?")).split("&"); |
38
|
|
|
for (var i = 0; i < paramList.length; i++) { |
39
|
|
|
if (paramList[i].toUpperCase().indexOf(paramName.toUpperCase() + "=") > -1 ) { |
40
|
|
|
return paramList[i].split("=")[1]; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
return false; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// This is used as a jQuery.get callback, but we don't use the arguments |
48
|
|
|
// (textStatus, jqXHR), so they are omitted here. |
49
|
|
|
function updateRefresh(data) { |
50
|
|
|
$('all > *', data).each(function(i, e) { |
51
|
|
|
if(e.tagName === 'JS') { |
52
|
|
|
$(e.childNodes).each(function(i, e) { |
53
|
|
|
if(e.tagName === 'EVAL') { |
54
|
|
|
exec($(e).text()); |
55
|
|
|
} |
56
|
|
|
else { |
57
|
|
|
if(e.tagName === 'ALERT') { |
58
|
|
|
$(JSON.parse($(e).text())).each(function(i, e) { |
59
|
|
|
alert(e); |
|
|
|
|
60
|
|
|
}); |
61
|
|
|
} |
62
|
|
|
window[e.tagName] = JSON.parse($(e).text()); |
63
|
|
|
} |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
else { |
67
|
|
|
$('#'+e.tagName).html($(e).text()); |
68
|
|
|
} |
69
|
|
|
}); |
70
|
|
|
refreshReady = true; |
71
|
|
|
if(ajaxRunning === true) { |
72
|
|
|
clearTimeout(updateRefreshTimeout); |
73
|
|
|
updateRefreshTimeout = setTimeout(updateRefreshRequest, refreshSpeed); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function updateRefreshRequest() { |
78
|
|
|
if(ajaxRunning === true && refreshReady === true) { |
79
|
|
|
refreshReady = false; |
80
|
|
|
xmlHttpRefresh = $.get('', {sn:sn, ajax:1}, updateRefresh, 'xml'); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
//Chess |
86
|
|
|
/*global availableMoves:true, submitMoveHREF:true */ |
87
|
|
|
var highlightMoves; |
88
|
|
|
|
89
|
|
|
function submitMove(data) { |
90
|
|
|
var e = $(this); |
91
|
|
|
data.toX = e.data('x'); |
92
|
|
|
data.toY = e.data('y'); |
93
|
|
|
$.get(submitMoveHREF, data, function(data) { |
|
|
|
|
94
|
|
|
sn = getURLParameter('sn', submitMoveHREF); |
|
|
|
|
95
|
|
|
highlightMoves(); |
96
|
|
|
updateRefresh(data); |
97
|
|
|
}, 'xml'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
function bindOne(func, arg) { |
101
|
|
|
return function() { |
102
|
|
|
return func.call(this, arg); |
103
|
|
|
}; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
window.highlightMoves = highlightMoves = function() { |
107
|
|
|
var e, x, y, boundSubmitMove, highlighted = $('.chessHighlight'); |
108
|
|
|
if(highlighted.length === 0) { |
109
|
|
|
e = $(this); |
110
|
|
|
x = e.data('x'); |
111
|
|
|
y = e.data('y'); |
112
|
|
|
boundSubmitMove = bindOne(submitMove, {x:x,y:y}); |
113
|
|
|
$(availableMoves[y][x]).addClass('chessHighlight').each(function(i, e) { |
|
|
|
|
114
|
|
|
e.onclick = boundSubmitMove; |
115
|
|
|
}); |
116
|
|
|
} |
117
|
|
|
else { |
118
|
|
|
highlighted.removeClass('chessHighlight').each(function(i, e){ |
119
|
|
|
e.onclick = highlightMoves; |
120
|
|
|
}); |
121
|
|
|
} |
122
|
|
|
}; |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
//Globals |
126
|
|
|
window.startRefresh = function(_refreshSpeed) { |
127
|
|
|
// If auto-refresh is disabled in preferences, then this function is not called, |
128
|
|
|
// so make sure the refresh is enabled ONLY if this function is called. |
129
|
|
|
disableStartAJAX = false; |
130
|
|
|
|
131
|
|
|
if(!_refreshSpeed) { |
132
|
|
|
return; |
133
|
|
|
} |
134
|
|
|
refreshSpeed = _refreshSpeed; |
135
|
|
|
sn = getURLParameter('sn', location.href); |
136
|
|
|
if(sn===false) { |
137
|
|
|
return; |
138
|
|
|
} |
139
|
|
|
// Delay before first AJAX udpate |
140
|
|
|
updateRefreshTimeout = setTimeout(updateRefreshRequest, refreshSpeed); |
141
|
|
|
}; |
142
|
|
|
|
143
|
|
|
// The following section attempts to prevent users from taking multiple |
144
|
|
|
// actions within the same page. Possible actions include: |
145
|
|
|
// |
146
|
|
|
// 1. Pressing a hotkey |
147
|
|
|
// 2. Submitting a form |
148
|
|
|
// 3. Clicking a link |
149
|
|
|
// |
150
|
|
|
// We need to ensure that doing any one of these actions prevents all |
151
|
|
|
// other actions from having any effect. The next three functions |
152
|
|
|
// attempt to accomplish this. |
153
|
|
|
// |
154
|
|
|
var linkFollowed = false; |
155
|
|
|
window.followLink = function(href) { |
156
|
|
|
"use strict"; |
157
|
|
|
// Prevent further actions after a hotkey is pressed. |
158
|
|
|
return function() { |
159
|
|
|
if(linkFollowed !== true) { |
160
|
|
|
linkFollowed = true; |
161
|
|
|
location.href = href; |
162
|
|
|
stopAJAX(); |
163
|
|
|
} |
164
|
|
|
}; |
165
|
|
|
}; |
166
|
|
|
$(function() { |
167
|
|
|
// Prevent further actions after a form is submitted. |
168
|
|
|
$('form').submit(function(e) { |
169
|
|
|
if (linkFollowed === true) { |
170
|
|
|
e.preventDefault(); |
171
|
|
|
} else { |
172
|
|
|
linkFollowed = true; |
173
|
|
|
stopAJAX(); |
174
|
|
|
} |
175
|
|
|
}); |
176
|
|
|
// Prevent further actions after a link is clicked. |
177
|
|
|
// This is skipped if the link has a "target" attribute specified. |
178
|
|
|
$('a[href]:not([target])').click(function(e) { |
179
|
|
|
// Did we click the link with the left mouse button? |
180
|
|
|
// We don't want to trigger this on right/middle clicks. |
181
|
|
|
if(e.which !== 1) { |
182
|
|
|
return; |
183
|
|
|
} |
184
|
|
|
// Don't trigger if clicked link has a no-op href attribute. |
185
|
|
|
if (this.href === 'javascript:void(0)') { |
186
|
|
|
return; |
187
|
|
|
} |
188
|
|
|
if(linkFollowed !== true) { |
189
|
|
|
linkFollowed = true; |
190
|
|
|
location.href = this.href; |
191
|
|
|
stopAJAX(); |
192
|
|
|
} |
193
|
|
|
e.preventDefault(); |
194
|
|
|
}); |
195
|
|
|
}); |
196
|
|
|
|
197
|
|
|
window.ajaxLink = function(link) { |
198
|
|
|
$.get(link, {ajax: 1}, function(data) { |
199
|
|
|
sn = getURLParameter('sn', link); |
200
|
|
|
updateRefresh(data); |
201
|
|
|
}, 'xml'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
window.toggleWepD = function(link) { |
205
|
|
|
"use strict"; |
206
|
|
|
$('.wep1:visible').slideToggle(600); |
207
|
|
|
$('.wep1:hidden').fadeToggle(600); |
208
|
|
|
$.get(link, {ajax: 1}); |
209
|
|
|
}; |
210
|
|
|
|
211
|
|
|
window.toggleScoutGroup = function(senderID) { |
212
|
|
|
$('#group'+senderID).toggle(); |
213
|
|
|
}; |
214
|
|
|
})(); |
215
|
|
|
|